package com.itheima.Service.ServiceImpl;

import com.itheima.Service.AdminLoginService;
import com.itheima.mapper.AdminLoginMapper;
import com.itheima.pojo.LoginDto;
import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.StoreEmp;
import com.itheima.pojo.User;
import com.itheima.properties.JwtTokenManagerProperties;
import com.itheima.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

@Service
public class AdminLoginServiceImpl implements AdminLoginService {

    @Autowired
    private AdminLoginMapper adminLoginMapper;

    /***
     * 管理端登录
     * @param dto
     * @return
     */
    @Override
    public LoginInfo login(LoginDto dto) {
        StoreEmp emp= adminLoginMapper.login(dto);
        if (ObjectUtils.isEmpty(emp)) {
            return null;
        }
        Map<String, Object> claims = new HashMap<>();
        claims.put("id", emp.getId());
        claims.put("username", emp.getUsername());

        String token = JwtUtils.generateJwt(claims);

        return new LoginInfo(token);

    }
}
